/**
 * Created by zhangb on 2015/10/18.
 */

function isArray(obj)
{
    return Object.prototype.toString.call(obj) === '[object Array]';
}

/**
 * 将nodelist对象转换为数组
 * @param nodes
 * @returns {*}
 */
function convertToArray(nodes)
{
    var array = null;
    try {
        array = Array.prototype.slice.call(nodes,0);
    } catch (ex) {
        array = new Array();
        for(var i=0 , len = array.length;i < len;i++)
        {
            array.push(nodes[i]);
        }
    }
    return array;
}

/**
 * 在现有元素之后插入新元素
 * @param newElement    新元素
 * @param targetElement 目标元素
 */
function insertAfter(newElement,targetElement)
{
    var parenet = targetElement.parentNode;
    if(parenet.lastChild == targetElement)
    {
        parenet.appendChild(newElement);
    }else{
        parenet.insertBefore(newElement,targetElement.nextSibling);
    }
}
//var oDiv = document.getElementById('oDiv');
//var oPara = document.createElement('p');
//var para = document.createTextNode('This is ');
//oDiv.appendChild(oPara);
//oPara.appendChild(para);
//
//var oEm = document.createElement('em');
//var sText = document.createTextNode('my ');
//oPara.appendChild(oEm);
//oEm.appendChild(sText);
//
//var para2 = document.createTextNode('content');
//oPara.appendChild(para2);
//
//var oh1 = document.createElement('h1');
//var ph1  = document.createTextNode('insertBefore');
//oh1.appendChild(ph1);
////oDiv.insertBefore(oh1,oPara);
//insertAfter(oh1,oPara);

